<?php

require_once(dirname(__FILE__)."/dao.php");
class UserDao extends Dao
{
    
    public function __construct()
    {
        parent::__construct();
        $this->_table = "tbl_userinfo";
    }

    # add a new user
    public function addUser($username, $passwd, $email)
    {
        $ret = $this->getUser($username); 
        if (!empty($ret))
        {
            #print "user exists".PHP_EOL;
            return null;
        }

        $sql = sprintf("INSERT INTO %s (username, passwd, email ) VALUES ('%s', '%s', '%s')", $this->_table, $username, $passwd, $email); 
        #echo $sql;

        $ret = $this->_query($sql);
        return 0;
        //return $ret;
    }

    public function setGesture($username, $strGesture)
    {
        $ret = $this->getUser($username); 
        if (empty($ret))
        {
            #print "user exists".PHP_EOL;
            return null;
        }

        $sql = sprintf("UPDATE %s SET gesture = '%s' WHERE username = '%s'", $this->_table, $strGesture, $username); 
        $ret = $this->_query($sql);
        return 0;
        //return $ret;
    }

    public function getUser($username)
    {
        $sql = sprintf("SELECT * FROM %s WHERE username = '%s'", $this->_table, $username);

        $ret = $this->_query($sql);
        if ($ret)
        {
            return $ret[0];
        }
        return null;
    }

};



